﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using KMF.Common;

namespace KMF.DAL
{
    public partial class TagDb
    {
        public static List<TagDto> GetTagName(string tagName)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_Admin_Tag_GetTagName");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@TagName", tagName));
                var result = dao.GetDTOList<TagDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }
        public static List<TagMapDto> GetTagMap(string MapId, string TagId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_Admin_TagMap_GetByMapIdAndTagId");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@MapId", MapId));
                command.Parameters.Add(dao.CreateParameter("@TagId", TagId));
                var result = dao.GetDTOList<TagMapDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }

        public static List<TagDto> GetTagNameByMapId(string MapId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_Admin_Tag_GetTagByMapId");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@MapId", MapId));
                var result = dao.GetDTOList<TagDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }
        public static int DelTagMapByMapId(string MapId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_Admin_TagMap_DelByMapId");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@MapId", MapId));
                var result = command.ExecuteNonQuery();
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }

    }
}
